import os

from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType
from langchain.llms import OpenAI
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

openai_api_base = "http://www.xiuwen.work:6002/v1"
openai_api_key = "test"
os.environ["SERPAPI_API_KEY"] = 'd329aa9848c97a69d8ad344dddf28af5dd8ab50e7ea1aa6271cb8c1ee94f4417'
# 作者：AI研习所 https://www.bilibili.com/read/cv24305261/ 出处：bilibili
llm = OpenAI(streaming=True, callbacks=[StreamingStdOutCallbackHandler()], temperature=0,
             openai_api_base=openai_api_base, openai_api_key=openai_api_key)

tools = load_tools(['serpapi', 'llm-math'], llm=llm)
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=False)
agent.run("88*99-2222")